package util

import (
	"crypto/md5"
	"crypto/sha1"
	"fmt"
	"hash"
	"io"
)

func MD5(reader io.Reader) string {
	return calc(md5.New(), reader)
}

func SHA1(reader io.Reader) string {
	return calc(sha1.New(), reader)
}

func calc(hash hash.Hash, reader io.Reader) string {
	if reader != nil {
		_, err := io.Copy(hash, reader)
		if err == nil {
			return fmt.Sprintf("%X", hash.Sum(nil))
		}
	}
	return ""
}
